package com.raysdata.smartcity.web.sys;

import com.raysdata.smartcity.HelperClazz;
import com.raysdata.smartcity.dto.Log;
import com.raysdata.smartcity.dto.User;
import com.raysdata.smartcity.web.BaseController;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by liux on 2017/3/14.
 */
@Controller
@RequestMapping(value = "/log")
public class LogController extends BaseController{

    @RequestMapping(value = "/toLogIndex", method = RequestMethod.GET)
    public String toLogIndex(Model model, HttpServletRequest request, HttpServletResponse response) {
        return "smartcity/logManage/logList";
    }

    @RequestMapping(value = "/getLogList")
    public void getLogList(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException {
        Map filter= WebUtils.getParametersStartingWith(request, "query_");
        Log log=new Log();
        BeanUtils.populate(log, filter);
        List<Log> logs = new ArrayList<Log>();
        int page = HelperClazz.getCurrentPage(request);
        int count = HelperClazz.getPageSize(request);
        User user=(User)request.getSession().getAttribute("LoginUser");
        logs = logDao.queryLog(page,count,log);
        HelperClazz.renderJson(response,HelperClazz.toJSON4Page(logs));
    }
}
